#ifndef SNLBPEvaluator_h__
#define SNLBPEvaluator_h__
//-----------------------------------------------------------
#include "SNFeatureEvaluator.h"

#define SN_SUM_OFFSETS( p0, p1, p2, p3, rect, step )                      \
	/* (x, y) */                                                          \
	(p0) = (rect).x + (step)* (rect).y;                                  \
	/* (x + w, y) */                                                      \
	(p1) = (rect).x + (rect).width + (step)* (rect).y;                   \
	/* (x + w, y) */                                                      \
	(p2) = (rect).x + (step)* ((rect).y + (rect).height);                \
	/* (x + w, y + h) */                                                  \
	(p3) = (rect).x + (rect).width + (step)* ((rect).y + (rect).height);

#define SN_TILTED_OFFSETS( p0, p1, p2, p3, rect, step )                   \
	/* (x, y) */                                                          \
	(p0) = (rect).x + (step)* (rect).y;                                  \
	/* (x - h, y + h) */                                                  \
	(p1) = (rect).x - (rect).height + (step)* ((rect).y + (rect).height); \
	/* (x + w, y + w) */                                                  \
	(p2) = (rect).x + (rect).width + (step)* ((rect).y + (rect).width);  \
	/* (x + w - h, y + w + h) */                                          \
	(p3) = (rect).x + (rect).width - (rect).height                        \
	+ (step)* ((rect).y + (rect).width + (rect).height);

class SNLBPEvaluator : public SNFeatureEvaluator
{
public:
	SNLBPEvaluator();
	~SNLBPEvaluator();

	virtual void Init(const SNFeatureParams* feature_params, int max_sample_count, cv::Size win_size);
	virtual void SetImage(const cv::Mat& img, uchar cls_label, int idx);

	virtual float operator()(int featureIdx, int sampleIdx) const
	{
		return (float)Features[featureIdx].Calc(Sum, sampleIdx);
	}

	virtual void WriteFeatures(cv::FileStorage& fs, const cv::Mat& feature_map) const;

protected:
	virtual void GenerateFeatures();

	class Feature
	{
	public:
		Feature();
		Feature(int offset, int x, int y, int block_w, int block_h);
		inline uchar Calc(const cv::Mat& sum, size_t y) const;
		void Write(cv::FileStorage &fs) const;

		cv::Rect Rect;
		int p[16];
	};

	std::vector<Feature> Features;

	cv::Mat Sum;
};
//-----------------------------------------------------------

#endif // SNLBPEvaluator_h__

